package edu.neusoft.springmvc.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import edu.neusoft.springmvc.model.Course;
import edu.neusoft.springmvc.model.Student;
import edu.neusoft.springmvc.model.User;
import edu.neusoft.springmvc.service.StudentService;
import edu.neusoft.springmvc.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {

  @Resource
  private UserService userService;

  @Resource
  private StudentService studentService;

  @RequestMapping("/stu")
  public String getStudent() {
    Student student = studentService.findStuByIdcard("100000");
    System.out.println("student:" + student.getStuName());
    for (int i = 0; i < student.getCourseList().size(); i++) {
      Course course = student.getCourseList().get(i);
      System.out.println("course:" + course.getCourseName());
    }
    return "success";
  }

  @RequestMapping(value = "/{id}")
  public String getUser(@PathVariable("id") Integer id, ModelMap model) {
    User user = this.userService.getUserById(id);
    model.addAttribute("user", user);
    return "showUser";
  }
}
